//
//  WSListCell.m
//  GroupFourFM
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSListCell.h"

@interface WSListCell ()

@property (nonatomic, strong) UIImageView *newsPic;
@property (nonatomic, strong) WSBaseTitleLabel *newsTitle;
@property (nonatomic, strong) UILabel *newsDigest;
@property (nonatomic, strong) UILabel *contentCount;
@property (nonatomic, strong) UIButton *nextBtn;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation WSListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createCell];
        self.isShowLine = NO;
    }
    
    return self;
}

-(void)createCell
{
    self.newsPic = [[UIImageView alloc] init];
    self.newsPic.backgroundColor = CLEAR;
    [self.contentView addSubview:self.newsPic];
    [self.newsPic mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(@10);
        make.bottom.mas_equalTo(@(-10));
        make.width.equalTo(self.contentView.mas_height).offset(-20);
    }];
    
    self.newsTitle = [[WSBaseTitleLabel alloc] init];
    self.newsTitle.backgroundColor = CLEAR;
    self.newsTitle.textColor = [UIColor colorWithRed:0.13 green:0.13 blue:0.13 alpha:1];
    self.newsTitle.font = [UIFont systemFontOfSize:19];
    [self.contentView addSubview:self.newsTitle];
    [self.newsTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.newsPic);
        make.right.mas_equalTo(@(-40));
        make.height.equalTo(self.newsPic).multipliedBy(0.4);
    }];
    
    self.newsDigest = [[UILabel alloc] initWithFrame:CGRectMake(self.newsPic.frame.origin.x + self.newsPic.frame.size.width + 10 ,self.newsTitle.frame.origin.y + self.newsTitle.frame.size.height + 10, 200*WID, 20*HEI)];
    self.newsDigest.backgroundColor = CLEAR;
    self.newsDigest.font = [UIFont systemFontOfSize:16 weight:0];
    [self.contentView addSubview:self.newsDigest];
    self.newsDigest.textColor = [UIColor lightGrayColor];
    self.newsDigest.numberOfLines = 2;
    [self.newsDigest mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.newsTitle.mas_bottom);
        make.right.equalTo(self.newsTitle);
        make.height.equalTo(self.newsPic).multipliedBy(0.3);
    }];
    
    self.contentCount = [[UILabel alloc] initWithFrame:CGRectMake(self.newsPic.frame.origin.x + self.newsPic.frame.size.width + 10 , self.newsDigest.frame.origin.y + self.newsDigest.frame.size.height + 10, 70*WID, 20*HEI)];
    self.contentCount.backgroundColor = CLEAR;
    self.contentCount.font = [UIFont systemFontOfSize:16 weight:0];
    [self.contentView addSubview:self.contentCount];
    self.contentCount.textAlignment = NSTextAlignmentLeft;
    self.contentCount.textColor = [UIColor lightGrayColor];
    [self.contentCount mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsDigest);
        make.top.equalTo(self.newsDigest.mas_bottom);
        make.right.equalTo(self.newsDigest);
        make.height.equalTo(self.newsPic).multipliedBy(0.3);
    }];
    
    self.nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nextBtn.backgroundColor = CLEAR;
    [self.nextBtn setImage:[UIImage imageNamed:@"findcell_arrow"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.nextBtn];
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(@(-20));
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(@20);
        make.width.mas_equalTo(@10);
    }];
    
    self.lineView = [[UIView alloc] init];
    self.lineView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
    [self.contentView addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsTitle);
        make.bottom.equalTo(self.contentView);
        make.right.mas_equalTo(@0);
        make.height.mas_equalTo(@1);
    }];
    self.lineView.hidden = !self.isShowLine;
}

-(void)setTopModel:(WSTopListModel *)topModel
{
    _topModel = topModel;
    self.lineView.hidden = !self.isShowLine;
    NSURL *url = [NSURL URLWithString:topModel.coverPath];
    [self.newsPic sd_setImageWithURL:url placeholderImage:PLACEHOLDER_CELL_SAME];
    self.newsTitle.text = topModel.title;
    self.newsDigest.text = [NSString stringWithFormat:@"1 %@",topModel.firstTitle];
    self.contentCount.text = [NSString stringWithFormat:@"2 %@",topModel.firstTitle];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
